package com.ops.service.ns.system.helper;

import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.ops.service.ns.system.constant.OPSConstant;
import com.ops.service.ns.system.exception.OPSException;

public final class OPSHelper {
	
	private OPSHelper()
	{
		
	}
	
	public static Date createSQLDate(String inputDate, String dateFormat){
		Date sqldate = null;
		if(inputDate == null || (inputDate != null && inputDate.equals(""))) {
			return null;
		}
		try {
			SimpleDateFormat sdf1 = new SimpleDateFormat(dateFormat);
			java.util.Date date = sdf1.parse(inputDate);
			sqldate = new java.sql.Date(date.getTime());
		} catch(Exception ex) {
			return null;
		}
		return sqldate;
	}	
	
	public static String inputToDBDateFormat(String inputDate, String sourceDateFormat, String destinationDateFormat) throws OPSException {
		String sqldate = null;
		if(inputDate == null || (inputDate != null && inputDate.equals(""))) {
			return null;
		}
		try {
			SimpleDateFormat sdf1 = new SimpleDateFormat(sourceDateFormat);
			java.util.Date date = sdf1.parse(inputDate);
			DateFormat formatter = new SimpleDateFormat(destinationDateFormat);
			sqldate = formatter.format(date);			
		} catch(Exception ex) {
	    	 throw new OPSException(OPSConstant.geterror_CODE_WAS_ERROR_GENERIC(),
	    			OPSConstant.getsystem_WAS(),
	    			OPSConstant.geterror_TYPE_TECHNICAL(),
					OPSConstant.geterror_CODE_WAS_ERROR_DESC() + OPSConstant.geterror_CODE_WAS_INVALID_DATE_ERROR_DESC() +inputDate);
		}
		return sqldate;
	}	
	
	public static boolean isLong(String input){
		if(input == null || (input != null && input.equals(""))){
			return false;
		}
		try {
			new Long(input);
		}catch(Exception ex){
			return false;
		}
		return true;
	}
	
}
